from threading import Thread, Lock
import time

tLock = Lock()

def timer(name, delay, repeat):
    tLock.acquire()
    print "Name : " + name + " started"
    while repeat > 0:
        time.sleep(delay)
        print name + " : " + str(repeat) + " " + str(time.ctime(time.time()))
        repeat -= 1
    print "Name : " + name + " releasing lock"
    tLock.release()
    print "Name : " + name + " terminated"
    
def main():
    thread_1 = Thread(target = timer, args = ("Timer 1", 1, 5))
    thread_2 = Thread(target = timer, args = ("Timer 2", 1, 5))
    thread_1.start()
    thread_2.start()    
    print "Main completed"
    
if __name__ == '__main__':
    main()
    
        